<?php

require_once("MDB2.php");

class Bug {
	public $bugId;
	public $title;
	public $description;
	public $status;
	public $priority;
	public $type;
	
	public function isResolved() {
		return $this->status == 1;
	}
}

class BugsBean {
	private $bugs;

	public function getBugs() {
		if( $this->bugs == null ) {
			$db = MDB2::connect("pgsql://phpfaces_info@localhost/phpfaces_info");
			$sql = "SELECT * FROM bugs";
			$res = $db->query( $sql );
			
			if( PEAR::isError( $res ) ) {
				print_r( $res );
				return null;
			}
			
			$bugs = array();
			while( $row = $res->fetchRow( MDB2_FETCHMODE_ASSOC ) ) {
				$bug = new Bug();
				$bug->bugId = $row["bug_id"];
				$bug->title = $row["title"];
				$bug->description = $row["description"];
				$bug->priority = $row["priority"];
				$bug->status = $row["status"];
				$bug->type = $row["type"];
				
				$bugs[] = $bug;
			}
			$this->bugs = $bugs;
		}
		return $this->bugs;
		
		
	}
}

?>